package it.uniroma2.art.coda.iraexample;

import it.uniroma2.art.coda.core.UIMACODAUtilities;
import it.uniroma2.art.coda.interfaces.IdentityResolverInterface;
import it.uniroma2.art.coda.projectionrule.PlaceholderStruct;
import it.uniroma2.art.coda.projectionrule.ProjectionRule;
import it.uniroma2.art.coda.structures.BindLabelToExistingARTURIResource;
import it.uniroma2.art.owlart.exceptions.ModelAccessException;
import it.uniroma2.art.owlart.model.ARTURIResource;
import it.uniroma2.art.owlart.utilities.ModelUtilities;

import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.apache.uima.jcas.tcas.Annotation;

public class DefIdRes extends IdentityResolverInterface{
	
	public DefIdRes(String id, String description) {
		super(id, description);
	}

	public BindLabelToExistingARTURIResource invokeComponent() {
		//Collection<IRASingleHint> uriResProbList = new ArrayList<IRASingleHint>();
		
		UIMACODAUtilities uimaCodaUtilities = new UIMACODAUtilities();
		Annotation ann = casAnn.getAnnotation();
		//String annotationText = ann.getCoveredText();
		//int begin = ann.getBegin();
		//int end = ann.getEnd();
		
		BindLabelToExistingARTURIResource bindLabels = new BindLabelToExistingARTURIResource();
		
		/*
		if(selProjRules.getProjRuleList().size() == 0)
			return bindLabels;
		try{
			List<ProjectionRule> selProjRulesList = selProjRules.getProjRuleList();
			for(int i=0; i<selProjRulesList.size(); ++i){
				ProjectionRule projRule = selProjRulesList.get(i);
				Map <String, PlaceholderStruct> placeholderMap = projRule.getPlaceholderMap();
				Iterator <PlaceholderStruct>nodeIter= placeholderMap.values().iterator();
				
				while(nodeIter.hasNext()){
					PlaceholderStruct placeholder = nodeIter.next();
					if(placeholder.isAlias())
						continue;
					if(placeholder.getType().compareToIgnoreCase("uri") != 0)
						continue;
					ARTURIResource uriRes;
					//check if the placeholder has a if/else structure in itself
					if (placeholder.hasIfElse()) {
						// if the placeholder has at least one if/struct then I just skip it because to 
						// evaluate it I need the aliases that I don't have (I need to resolve them) 
						continue;
					}
					List<String> valueList;
					valueList = uimaCodaUtilities.getValueOfFeatureFromFeatPath(ann, placeholder);
					if(valueList == null)
						continue;
					//check the ontology to see if in it there is already a resource that can be used
					for(String value : valueList){
						uriRes = rdfModel.createURIResource(rdfModel.getDefaultNamespace()+value);
						if(uriRes == null || ModelUtilities.checkExistingResource(rdfModel, uriRes) == false)
							continue;
						bindLabels.addBindLabelARTURIResource(placeholder, value, uriRes);
					}
				}
			}
		} catch (ModelAccessException e) {
			e.printStackTrace();
		}*/
		
		return bindLabels;
	}
	
	

}

